<include file="./Template/Admin/header.html" title="添加产品" />
<link rel="stylesheet" type="text/css" href="__ADMIN__css/plugins/webuploader/webuploader.css" />
<link rel="stylesheet" type="text/css" href="__ADMIN__js/plugins/webuploader/style.css" />
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>添加产品</h5>
                </div>
                <div class="ibox-content">
                    <div class="row m-b-sm m-t-sm">
                        <div class="col-md-2">
                            <a href="{:U('Admin/product/index')}" class="btn btn-outline btn-primary">返回产品列表</a>
                        </div>
                    </div>
                    <form class="form-horizontal m-t" id="addForm" enctype="multipart/form-data" action="{:U('Admin/Product/Save')}">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">产品名称:</label>
                            <div class="col-sm-8">
                                <input id="title" name="title" class="form-control" type="text" value="{$productInfo.title}" aria-required="true" aria-invalid="false" class="valid">
                                <input id="id" name="id" value="{$productInfo.id}" class="form-control" type="hidden">
                                <span class="help-block m-b-none"></span>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <!--<div class="form-group">-->
                            <!--<label class="col-sm-3 control-label">产品图片:</label>-->
                            <!--<div class="col-sm-8">-->
                                <!--<input id="images" name="images" class="form-control" type="file" aria-required="true" aria-invalid="false" class="valid">-->
                            <!--</div>-->
                        <!--</div>-->
                        <div class="form-group">
                            <label class="col-sm-3 control-label">产品图片：</label>
                            <input type="hidden" id="images" name="images" value="">
                            <div class="col-sm-8 control-label">
                                <div id="uploader">
                                    <div class="queueList">
                                        <div id="dndArea" class="placeholder">
                                            <div id="filePicker"></div>
                                            <p>或将照片拖到这里，单次最多可选300张</p>
                                        </div>
                                    </div>
                                    <div class="statusBar" style="display:none;">
                                        <div class="progress">
                                            <span class="text">0%</span>
                                            <span class="percentage"></span>
                                        </div>
                                        <div class="btns">
                                            <div id="filePicker2"></div><div class="uploadBtn">开始上传</div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">产品类别:</label>
                            <div class="col-sm-8">
                                <select class="form-control m-b" name="cate_id">
                                    <option>-----请为产品选择所属类别-----</option>
                                    <foreach name="category" item="v">
                                        <option value="{$v.id}">{$v.html}{$v.title}</option>
                                    </foreach>
                                </select>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">年份:</label>
                            <div class="col-sm-8">
                                <input id="years" name="years" value="{$productInfo.years}" class="form-control" type="text">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">尺寸:</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" value="{$productInfo.size}" name="size" id="size" />
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">重量:</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" value="{$productInfo.weight}" name="weight" id="weight" />
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">关键词:</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" value="{$productInfo.keyword}" name="keyword" id="keyword" aria-required="true" aria-invalid="false" class="valid"/>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">产品介绍:</label>
                            <div class="col-sm-8">
                                <!-- 加载编辑器的容器 -->
                                <script id="content" name="content" type="text/plain" >{$productInfo.content}</script>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">联系电话:</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" value="<if condition="$productInfo['tel'] == ''">400-088-9783<else />{$productInfo.tel}</if>" name="tel" id="tel" aria-required="true" aria-invalid="false" class="valid"/>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-8 col-sm-offset-3">
                                <button class="btn btn-primary" type="submit">提交</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>



<script src="__ADMIN__js/jquery.min.js"></script>
<script src="__ADMIN__js/bootstrap.min.js"></script>
<script src="__ADMIN__js/plugins/layer.3/layer.js"></script>
<script src="__ADMIN__js/common.js"></script>
<script src="__ADMIN__js/content.min.js"></script>
<script src="__ADMIN__js/plugins/validate/jquery.validate.min.js"></script>
<script src="__ADMIN__js/plugins/validate/messages_zh.min.js"></script>
<script src="__ADMIN__js/plugins/switchery/switchery.js"></script>

<script type="text/javascript" src="__ADMIN__js/plugins/webuploader/webuploader.js"></script>
<script type="text/javascript" src="__ADMIN__js/plugins/webuploader/upload.js"></script>
<script type="text/javascript" src="__ADMIN__plugins/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="__ADMIN__plugins/ueditor/ueditor.all.js"></script>

<script>
    var elem = document.querySelector('.js-switch');
    var init = new Switchery(elem);

    var ue = UE.getEditor('content');

    $(function(){
        $.validator.setDefaults({
            highlight: function (e) {
                $(e).closest(".form-group").removeClass("has-success").addClass("has-error")
            }, success: function (e) {
                e.closest(".form-group").removeClass("has-error").addClass("has-success")
            }, errorElement: "span", errorPlacement: function (e, r) {
                e.appendTo(r.is(":radio") || r.is(":checkbox") ? r.parent().parent().parent() : r.parent())
            }, errorClass: "help-block m-b-none", validClass: "help-block m-b-none"
        }), $().ready(function () {
            var e = "<i class='fa fa-times-circle'></i> ";

            $("#addForm").validate({
                rules: {
                    title: "required",
                    keyword: "required",
                    content: "required",
                    tel: "required",
                    cate_id: "required"
                },
                messages: {
                    title: e + "请输入产品名称",
                    keyword: e + "请输入产品的关键词",
                    content: e + "请输入产品介绍",
                    tel: e + "请输入联系电话",
                    cate_id: e + "请为产品选择所属类别"
                },
                submitHandler: function(form){
                    var data = new  FormData(document.getElementById('addForm'));
                    $.ajax({
                        url:$(form).attr('action'),
                        type:"POST",
                        data:data,
                        cache: false,
                        processData:false,
                        contentType:false,
                        success:function(data){
                            if(data.status > 0){
                                common.error(data.msg);
                            }else{
                                common.success(data.msg,"{:U('Admin/Product/index')}");
                            }
                        },
                        dataType:'JSON'
                    });
                    return false;
                }
            });
        });

    });
</script>
</body>
</html>
